-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19216 - NamedEntityGraph annotation supporting Hibernate parseable format #9829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| * @apiNote Entity-name is used here rather than entity-class to allow | ||
| * for dynamic models. | ||
| */ | ||
| String rootEntityName() default ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better if there was a way to specify this as part of the mini-language itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It gets a little tricky. Syntactically what is the difference between MyEntity( someAttribute ) and someAttribute( someSubAttribute )?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about something like MyEntity: someAttribute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan was to simply have this pass through GraphParser. So if you are asking me if I want to change the GraphParser grammar, no not really.
If we don't change GraphParser, there would need to be a pre-analysis of this text to determine if there is a =n entity "prefix". I'm not against it, just not sure what it gains us. But if others think its "nicer", I'm fine with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should mention, I had planned to change this a bit to allow either name or class:
@interface NamedEntityGraph {
...
String rootEntityName() default "";
Class<?> rootEntityType() default void.class;Mainly because I know most users will prefer to use the class reference. I will agree that given just #rootEntityName your suggestion is nice.
6 in one, half dozen in the other imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about something like
MyEntity: someAttribute
So I did end up adding this to the parser syntax. But in practice, for the named graphs, this is only needed for package-level definition. For entity-level I just required that the annotation be placed on the root entity for the graph (in keeping with JPA variant) and so we always know the entity type there.
@Entity
@NamedEntityGraph( graph="title, isbn")
class Book {...}@NamedEntityGraph( name="book-title-isbn", graph="Book: title, isbn")
package org.hibernate.test;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For entity-level I just required that the annotation be placed on the root entity for the graph (in keeping with JPA variant) and so we always know the entity type there.
Perfect!
| @NamedEntityGraph( name = "test-id-name", graph = "(id, name)" ) | ||
| @NamedEntityGraph( name = "test-id-name-parent", graph = "(id, name, parent)" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed nice.
...src/main/java/org/hibernate/boot/models/annotations/internal/NamedEntityGraphAnnotation.java
Dismissed
Show dismissed
Hide dismissed
...src/main/java/org/hibernate/boot/models/annotations/internal/NamedEntityGraphAnnotation.java
Dismissed
Show dismissed
Hide dismissed
...src/main/java/org/hibernate/boot/models/annotations/internal/NamedEntityGraphAnnotation.java
Dismissed
Show dismissed
Hide dismissed
...rc/main/java/org/hibernate/boot/models/annotations/internal/NamedEntityGraphsAnnotation.java
Dismissed
Show dismissed
Hide dismissed
...rc/main/java/org/hibernate/boot/models/annotations/internal/NamedEntityGraphsAnnotation.java
Dismissed
Show dismissed
Hide dismissed
hibernate-core/src/main/java/org/hibernate/graph/internal/parse/GraphParsing.java
Fixed
Show fixed
Hide fixed
56f9d3b to
104edf2
Compare
hibernate-core/src/main/java/org/hibernate/boot/model/NamedGraphCreator.java
Fixed
Show fixed
Hide fixed
e0f848b to
7da9f64
Compare
...rnate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java
Fixed
Show fixed
Hide fixed
f827d8f to
0ea5bd8
Compare
…e format HHH-19237 - Expand graph language to optionally specify entity HHH-19217 - Expose GraphParser#parse on SessionFactory
eab7539 to
790774e
Compare
HHH-19216 - NamedEntityGraph annotation supporting Hibernate parseable format
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.